package com.hrs.core.controller;

import com.hrs.common.anno.NoValidPrivilege;
import com.hrs.common.constant.SwaggerConst;
import com.hrs.common.result.Result;
import com.hrs.core.service.DepartmentService;
import com.hrs.enity.ro.DepartmentAddRo;
import com.hrs.enity.ro.DepartmentUpdateRo;
import com.hrs.enity.vo.DepartmentVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author 摆渡人
 * @description
 * @date 2023/1/12 22:18
 */
@Api(tags = {SwaggerConst.Admin.MANAGER_DEPARTMENT})
@RestController
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    @ApiOperation(value = "查询部门树形列表", notes = "查询部门列表")
    @GetMapping("/department/tree")
    @NoValidPrivilege
    public Result<List<DepartmentVo>> listDepartment() {
        return departmentService.listDepartment();
    }

    @ApiOperation(value = "查询部门列表", notes = "查询部门列表")
    @GetMapping("/department/listAll")
    @NoValidPrivilege
    public Result<List<DepartmentVo>> listAll() {
        return departmentService.listAll();
    }

    @ApiOperation(value = "根据id获取部门信息", notes = "获取部门")
    @GetMapping("/department/query/{deptId}")
    @NoValidPrivilege
    public Result<DepartmentVo> getDepartment(@PathVariable Integer deptId) {
        return departmentService.getDepartmentById(deptId);
    }

    @ApiOperation(value = "添加部门", notes = "添加部门")
    @PostMapping("/department/add")
    @NoValidPrivilege
    public Result<String> addDepartment(@Validated @RequestBody DepartmentAddRo departmentAddRo) {
        return departmentService.addDepartment(departmentAddRo);
    }

    @ApiOperation(value = "更新部门信息", notes = "更新部门信息")
    @PostMapping("/department/update")
    @NoValidPrivilege
    public Result<String> updateDepartment(@Valid @RequestBody DepartmentUpdateRo departmentUpdateRo) {
        return departmentService.updateDepartment(departmentUpdateRo);
    }

    @ApiOperation(value = "删除部门", notes = "删除部门")
    @PostMapping("/department/delete/{deptId}")
    @NoValidPrivilege
    public Result<String> delDepartment(@PathVariable Integer deptId) {
        return departmentService.delDepartment(deptId);
    }

//    @ApiOperation(value = "查询部门及员工列表", notes = "查询部门及员工列表")
//    @GetMapping("/department/listEmployee")
//    public Result<List<DepartmentVo>> listDepartmentEmployee() {
//        return departmentService.listAllDepartmentEmployee(null);
//    }
//
//    @ApiOperation(value = "根据部门名称查询部门及员工列表", notes = "根据部门名称查询部门及员工列表")
//    @GetMapping("/department/listEmployeeByDepartmentName")
//    public Result<List<DepartmentVo>> listDepartmentEmployee(String departmentName) {
//        return departmentService.listAllDepartmentEmployee(departmentName);
//    }
//
//
//
//
//
//
//
//    @ApiOperation(value = "上下移动")
//    @GetMapping("/department/upOrDown/{deptId}/{swapId}")
//    public Result<String> upOrDown(@PathVariable Long deptId, @PathVariable Long swapId) {
//        return departmentService.upOrDown(deptId, swapId);
//    }
//
//    @ApiOperation(value = "升级")
//    @GetMapping("/department/upgrade/{deptId}")
//    public Result<String> upgrade(@PathVariable Long deptId) {
//        return departmentService.upgrade(deptId);
//    }
//
//    @ApiOperation(value = "降级")
//    @GetMapping("/department/downgrade/{deptId}/{preId}")
//    public Result<String> downgrade(@PathVariable Long deptId, @PathVariable Long preId) {
//        return departmentService.downgrade(deptId, preId);
//    }
}
